package com.lanyou.cook.camel.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.RowMapper;

import com.lanyou.cook.camel.entity.TesbBuIfSchedule;
import com.lanyou.cook.camel.util.ExceptionToStrFactory;

/**
 * 对数据t_esb_bu_if_schedule表操作的dao
 * @author ly-lihailang
 *
 */
public class ScheduleDao extends BaseDao<TesbBuIfSchedule>{
	
	private static Logger logger = Logger.getLogger(FtpServerDao.class);
	/**
	 * 自定义关系（t_esb_bu_if_schedule表）-对象（TesbBuIfSchedule）的映射
	 */
	RowMapper<TesbBuIfSchedule> mapper = new RowMapper<TesbBuIfSchedule>() {
		public TesbBuIfSchedule mapRow(ResultSet rs, int rowNum) throws SQLException {
			TesbBuIfSchedule rcd = new TesbBuIfSchedule();
			rcd.setIfScheduleId(rs.getString("IF_SCHEDULE_ID"));
			rcd.setIfScheduleName(rs.getString("IF_SCHEDULE_NAME"));
			rcd.setIfId(rs.getString("IF_ID"));
			rcd.setIfType(rs.getString("IF_TYPE"));
			rcd.setRunWay(rs.getString("RUN_WAY"));
			rcd.setRunCyc(rs.getInt("RUN_CYC"));
			rcd.setDayOfWeek(rs.getString("DAY_OF_WEEK"));
			rcd.setSkdBeginDate(rs.getDate("SKD_BEGIN_DATE"));
			rcd.setSkdEndDate(rs.getDate("SKD_END_DATE"));
//			rcd.setFileCachePath(rs.getString("FILE_CACHE_PATH"));
			rcd.setIsEnable(rs.getString("IS_ENABLE"));
			rcd.setCreator(rs.getString("CREATOR"));
			rcd.setCreatedDate(rs.getDate("CREATED_DATE"));
			rcd.setModifier(rs.getString("MODIFIER"));
			rcd.setLastUpdatedDate(rs.getDate("LAST_UPDATED_DATE"));
			return rcd;
		}
	};
	/**
	 * @param ifId 接口id
	 * @return 根据接口id查询到的定时任务
	 */
	public TesbBuIfSchedule findTesbBuIfScheduleByifId(String ifId) {
//		logger.info("[ScheduleDao.findTesbBuIfScheduleByifId]:ifId="+ifId);
		if(StringUtils.isNotBlank(ifId));
		String sql = "SELECT * FROM t_esb_bu_if_schedule WHERE IS_ENABLE='1' and if_id = ?";
		TesbBuIfSchedule tesbBuIfSchedule = new TesbBuIfSchedule();
		try{
			tesbBuIfSchedule = this.getJdbcTemplate().queryForObject(sql, mapper, ifId);
			return tesbBuIfSchedule;
		}catch(DataAccessException e){
			logger.error("[ScheduleDao.findTesbBuIfScheduleByifId]:ifId="+ifId+"---"+ExceptionToStrFactory.getErrorInfoFromException(e));
			return null;
		}
	};
}
